package com.herench.repost.entrance;


import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * Created by ThinkPad on 2017/8/14.
 */

@CrossOrigin(origins = "*", maxAge = 3600)
@Controller
@RequestMapping("/entrance")
public class HttpEntrance {

    private static final Logger logger = Logger.getLogger(HttpEntrance.class);


//    private String payUrl = "http://39.106.103.34:8081/pay/gateway/desService";

//    private String smsUrl = "http://39.106.103.34:9001/auth/entrance/service";

    @Value("${payUrl}")
    private String payUrl;
    //
    @Value("${smsUrl}")
    private String smsUrl;

    @RequestMapping(value = "/pay", produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String pay(@RequestBody final String originalMsg) {
        logger.info("request:" + originalMsg);
        String res = "";
        try {
            res = HttpClientSupport.doPost(payUrl, originalMsg, "UTF-8");
        } catch (Exception e) {
            logger.info("exception:" + e.getMessage());
            e.printStackTrace();
        }
        logger.info("response:" + res);
        return res;
    }

    @RequestMapping(value = "/sms", produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String sms(@RequestBody final String originalMsg) {
        logger.info("request:" + originalMsg);
        String res = "";
        try {
            res = HttpClientSupport.doPost(smsUrl, originalMsg, "UTF-8");
        } catch (Exception e) {
            logger.info("exception:" + e.getMessage());
            e.printStackTrace();
        }
        logger.info("response:" + res);
        return res;
    }

}
